package com.itheima.myenum.Demo2;

public class TestSeason {
    public static void main(String[] args) {
        System.out.println(Season.SPRING);
        System.out.println(Season.SUMMER);
        System.out.println(Season.AUTUMN);
        System.out.println(Season.WINTER);

        System.out.println("========================");

        // 获得枚举项的名称
        String name = Season.SPRING.name();
        System.out.println(name);
        System.out.println("========================");

        // 返回枚举项在枚举类中的索引值
        int index1 = Season.SPRING.ordinal();
        System.out.println(index1);
        int index2 = Season.SUMMER.ordinal();
        System.out.println(index2);
        System.out.println("========================");

        // 比较两个枚举项,返回的是索引值的差值
        int result = Season.SPRING.compareTo(Season.SUMMER);
        System.out.println("result = " + result);
        System.out.println("========================");

        // 返回枚举常量的名称
        String s = Season.SPRING.toString();
        System.out.println(s);
        System.out.println("========================");

        // 获取指定枚举类中的指定名称的枚举值
        Season spring = Enum.valueOf(Season.class, "SPRING");
        System.out.println(spring);
        System.out.println(Season.SPRING == spring);
        System.out.println("========================");

        // 获取所以的枚举项
        Season[] values = Season.values();
        for (Season value : values) {
            System.out.println(value);
        }
    }
}
